//
//  TableModel.m
//  ZHYYView
//
//  Created by MT-SW-005 on 2021/9/22.
//  Copyright © 2021 yuan zhang. All rights reserved.
//

#import "TableModel.h"
//#import "TableData.h"
@implementation TableModel

-(instancetype)initWithName:(NSString *)name ID:(NSString*)itemID DUT1:(NSString*)dut1 DUT2:(NSString*)dut2
{
    self = [super init];
    if (self) {
        _name = name;
        _ID =itemID;
        _DUT1 = dut1;
        _DUT2 = dut2;
    }
    return self;
}


+ (NSMutableArray<TableModel *> *)dataList:(NSString *)fileName
{
    NSMutableArray<TableModel *> *dataList = [NSMutableArray array];
    NSArray *List = [NSArray arrayWithContentsOfFile:fileName];
    for (NSDictionary *item in List) {
        TableModel *tbModel =[[TableModel alloc]initWithName:item[@"ItemName"] ID:item[@"ID"] DUT1:@"---" DUT2:@"---"];
        NSArray *subItems = item[@"SubItems"];
        [dataList addObject:tbModel];
        for (NSDictionary *dict in subItems) {
             TableModel *subtbModel =[[TableModel alloc]initWithName:dict[@"ItemName"] ID:dict[@"ID"] DUT1:@"---" DUT2:@"---"];
            [dataList addObject:subtbModel];
        }
    }

    return dataList;
}




- (NSString *)description
{
    return [NSString stringWithFormat:@"ID: %@; item:%@", self.ID, self.name];
}



@end
